package com.runtime.hongyunuser.bean.vo;

import com.runtime.hongyunuser.bean.Products;
import com.runtime.hongyunuser.bean.Shoppingcarts;
import com.runtime.hongyunuser.bean.Productimages;  // 新增导入
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CartProductVO {
    // 购物车项信息
    private Long cartId;
    private Long userId;
    private Long productId;  // 新增：明确购物车中的 productId
    private Long quantity;
    private String addedAt;

    // 产品信息
    private Long categoryId;
    private String productNumber;
    private String productName;
    private double price;
    private Long stock;
    private Long stockAlertThreshold;
    private Long isPublished;
    private String createdAt;
    private String updatedAt;

    // 图片信息（新增）
    private String imageUrl;
    private Long sortOrder;

    // 计算属性 - 商品小计
    public double getSubtotal() {
        return price * quantity;
    }

    // 构造方法 - 从 Shoppingcarts、Products 和 Productimages 对象构建（新增）
    public CartProductVO(Shoppingcarts cartItem, Products product, Productimages image) {
        // 初始化购物车项信息
        this.cartId = cartItem.getCartId();
        this.userId = cartItem.getUserId();
        this.productId = cartItem.getProductId();
        this.quantity = cartItem.getQuantity();
        this.addedAt = cartItem.getAddedAt();

        // 初始化产品信息
        this.categoryId = product.getCategoryId();
        this.productNumber = product.getProductNumber();
        this.productName = product.getProductName();
        this.price = product.getPrice();
        this.stock = product.getStock();
        this.stockAlertThreshold = product.getStockAlertThreshold();
        this.isPublished = product.getIsPublished();
        this.createdAt = product.getCreatedAt();
        this.updatedAt = product.getUpdatedAt();

        // 初始化图片信息（新增）
        if (image != null) {
            this.imageUrl = image.getImageUrl();
            this.sortOrder = image.getSortOrder();
        }
    }
}